package com.example.textview.listview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.example.textview.R;

public class ListviewActivity extends Activity {

    private ListView mLV1;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        mLV1=findViewById(R.id.lv_1);
        mLV1.setAdapter(new MylistAdapter(ListviewActivity.this));

        mLV1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(ListviewActivity.this,"pos"+i,Toast.LENGTH_SHORT).show();
            }
        });

            mLV1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Toast.makeText(ListviewActivity.this,"长按 pos"+i,Toast.LENGTH_SHORT).show();
                   // return false;
                    return true;
                }
            });

    }
}
